//
//  HNMyOrderViewController.m
//  baidaifu
//
//  Created by 朱传正 on 2016/12/30.
//  Copyright © 2016年 haoniu. All rights reserved.
//

#import "HNMyOrderViewController.h"
#import "HNMyOrderTableCell.h"
#import "HNOrderDetailController.h"
#import "HNPayTypeController.h"
#import "HNOrderConsultCell.h"
#import "OrderDetailController.h"

#define selectedRow_OriginalValue 5000
#define orderType_consult @"consult"
#define orderType_my @"my"



@interface HNMyOrderViewController ()<UITableViewDelegate,UITableViewDataSource,HNMyOrderTableCellDelegate,UIAlertViewDelegate>

//选项卡形态控制
@property (nonatomic,strong)UILabel *choiceLabel0;
@property (nonatomic,strong)UIView *choiceLineView0;
@property (nonatomic,strong)UILabel *choiceLabel1;
@property (nonatomic,strong)UIView *choiceLineView1;
@property (nonatomic,strong)UILabel *choiceLabel2;
@property (nonatomic,strong)UIView *choiceLineView2;
@property (nonatomic,strong)UILabel *choiceLabel3;
@property (nonatomic,strong)UIView *choiceLineView3;
@property (nonatomic,strong)UILabel *choiceLabel4;
@property (nonatomic,strong)UIView *choiceLineView4;

@property (nonatomic,assign)NSInteger choiceBtnTag;

@property (nonatomic,strong)NSMutableArray *docterListSource;

@property (nonatomic,assign)NSInteger docterListCount;

@property (nonatomic,assign) CGFloat currentTag;


@property (nonatomic,assign) NSInteger page;

@property (nonatomic,assign) NSInteger selectedRow;

@end

@implementation HNMyOrderViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
   
}

-(void)drawView{
     _docterListSource = [NSMutableArray array];
    _selectedRow = selectedRow_OriginalValue;
   
    [self setHeadSection];
    [self setStateColor:_choiceState];
    
    [self setOrderListView];
    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0.5)];
    lineLabel.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineLabel];
    

}

-(void)initData{
  
}

-(void)setHeadSection{
    
    _headSectionView.backgroundColor = [UIColor whiteColor];
    NSArray *nameArray = nil;
    if ([_orderType isEqualToString:orderType_my]) {
        nameArray = [NSArray arrayWithObjects:@"全部",@"待付款",@"待审核",@"已发货",@"已收货",nil];
    }else{
       nameArray = [NSArray arrayWithObjects:@"全部",@"待付款",@"已付款",@"服务中",@"已完成",nil];
    }
    
    
    for (int i = 0; i < nameArray.count; i++) {
        UIView *itemView = [[UIView alloc]initWithFrame:CGRectMake( kScreen_Width/nameArray.count * i, 0, kScreen_Width/nameArray.count,_headSectionView.frame.size.height)];
        [self.headSectionView addSubview:itemView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, itemView.frame.size.width, itemView.frame.size.height - 20)];
        label.tag = 100 + i;
        label.text = nameArray[i];
        label.textColor = RGBJ(50);
        label.textAlignment =  NSTextAlignmentCenter ;
        label.font = [UIFont systemFontOfSize:14];
        [itemView addSubview:label];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(5, itemView.frame.size.height - 1, itemView.frame.size.width-10,1)];
        lineView.tag = 500 + i;
        [lineView setHidden:YES];
        lineView.backgroundColor = RGB(253, 108, 110);
        [itemView addSubview:lineView];
        switch (i) {
            case 0:
                self.choiceLabel0 = label;
                self.choiceLineView0 = lineView;
                break;
            case 1:
                self.choiceLabel1 = label;
                self.choiceLineView1 = lineView;
                break;
            case 2:
                self.choiceLabel2 = label;
                self.choiceLineView2 = lineView;
                break;
            case 3:
                self.choiceLabel3 = label;
                self.choiceLineView3 = lineView;
                break;
            case 4:
                self.choiceLabel4 = label;
                self.choiceLineView4 = lineView;
                break;
                
            default:
                break;
        }
        //添加点击按钮 - 切换
        UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [clickBtn setTitle:@"" forState:UIControlStateNormal];
        [clickBtn setBackgroundColor:RGBA(255, 255, 255, 0)];
        [clickBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        clickBtn.frame = CGRectMake(0, 0, itemView.frame.size.width, itemView.frame.size.height);//大小和位置
        clickBtn.tag = 500 + i;
        [clickBtn addTarget:self action:@selector(clickInAction:) forControlEvents:UIControlEventTouchUpInside];//button被按下又抬起后发生的事件
        [itemView addSubview:clickBtn];
    }
    
}


//推荐、闲置、寄卖、代购选择后执行的方法
-(void)clickInAction:(UIButton *)btn{
    [self setStateColor:btn.tag - 500];

}

//选择按钮状态变换
-(void)setStateColor:(NSInteger)num{
    _choiceState = num;
    switch (num) {
        case 0://推荐
            self.choiceLabel0.textColor = RGB(253, 118, 110);
            [self.choiceLineView0 setHidden:NO];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
            self.choiceLabel4.textColor = RGBJ(77);
            [self.choiceLineView4 setHidden:YES];
            
            
            [self getDoctorMessage:num];//获取数据
            break;
        case 1://关注
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGB(253, 118, 110);
            [self.choiceLineView1 setHidden:NO];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
            self.choiceLabel4.textColor = RGBJ(77);
            [self.choiceLineView4 setHidden:YES];
            
            [self getDoctorMessage:num];//获取数据
            break;
        case 2://闲置
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGB(253, 118, 110);
            [self.choiceLineView2 setHidden:NO];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
            self.choiceLabel4.textColor = RGBJ(77);
            [self.choiceLineView4 setHidden:YES];
            
            [self getDoctorMessage:num];//获取数据
            break;
        case 3://闲置
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGB(253, 118, 110);
            [self.choiceLineView3 setHidden:NO];
            self.choiceLabel4.textColor = RGBJ(77);
            [self.choiceLineView4 setHidden:YES];
            
            
            [self getDoctorMessage:num];//获取数据
            break;
        case 4://闲置
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
            self.choiceLabel4.textColor = RGB(253, 118, 110);
            [self.choiceLineView4 setHidden:NO];
            
            [self getDoctorMessage:num];//获取数据
            break;
        default:
            break;
    }
    
}


-(void)setOrderListView{

    [_orderListTableView setBackgroundColor:RGB(236, 240, 241)];
    _orderListTableView.delegate = self;
    _orderListTableView.dataSource = self;
 
    [_orderListTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    //上拉刷新

    MJRefreshGifHeader *header = [[MJRefreshGifHeader alloc]init];
    
    [header setRefreshingBlock:^(void){
        [self getDoctorMessage:0];
    }];
    self.orderListTableView.mj_header = header;


}


#pragma -mark TableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger count = _docterListSource.count;
    
    NSLog(@"%ld",count);
    
//    if (!count) {
//        return 1;
//    }
    return _docterListSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([_orderType isEqualToString:orderType_my]) {
        return 163;
    }else{
        return 84.5;
    }
   
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *orderDic = _docterListSource[indexPath.row];
    
    if ([_orderType isEqualToString:orderType_my]) {
        static NSString *CellIdentifier = @"HNMyOrderTableCell";
        
        HNMyOrderTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        if (_docterListSource.count > 0) {
            cell.state = indexPath.row;
            cell.indexPath = indexPath;
            cell.MyOrderCellDelegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.cellTime.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"createTime"]];
            cell.cellOrderNum.text = [NSString stringWithFormat:@"订单号：%@",[orderDic objectForKey:@"orderSn"]];
            cell.cellPrice.text = [NSString stringWithFormat:@"¥%@",[orderDic objectForKey:@"money"]];
            
            NSArray *goodsArr = [NSArray arrayWithArray:[orderDic objectForKey:@"goods"]];
            if (goodsArr.count > 1) {
                NSArray * map = goodsArr;
                for (int i=0; i<map.count; i++) {
                    if (i == 0) {
                        NSDictionary * dict = map[i];
                  
                        NSString * prodImg = [NSString stringWithFormat:@"%@%@",url_Base,[dict objectForKey:@"goodsImg"]];
                        [cell.cellImage sd_setImageWithURL:[NSURL URLWithString:prodImg] placeholderImage:[UIImage imageNamed:@"shopping_image"]];
    
                    }else if(i == 1){
                        NSDictionary * dict = map[i];
                        
                        NSString * prodImg = [NSString stringWithFormat:@"%@%@",url_Base,[dict objectForKey:@"goodsImg"]];
                        [cell.cellImage2 setHidden:NO];
                        [cell.cellImage2 sd_setImageWithURL:[NSURL URLWithString:prodImg] placeholderImage:[UIImage imageNamed:@"shopping_image"]];
                    }else if(i == 2){
                        NSDictionary * dict = map[i];
                        
                        NSString * prodImg = [NSString stringWithFormat:@"%@%@",url_Base,[dict objectForKey:@"goodsImg"]];
                        [cell.cellImage3 setHidden:NO];
                        [cell.cellImage3 sd_setImageWithURL:[NSURL URLWithString:prodImg] placeholderImage:[UIImage imageNamed:@"shopping_image"]];
                    }else{
                        break;
                    }
                }
                [cell.cellDescribe setHidden:YES];
                [cell.allAmountLabel setHidden:NO];
//                int allAmount = 0;
//                for (int i = 0; i<goodsArr.count; i ++) {
//                    NSDictionary * dict = map[i];
//                    int  prodCount = [[NSString stringWithFormat:@"%@",[dict objectForKey:@"goodsNumber"]] intValue];
//                    allAmount = allAmount + prodCount;
//                }
                cell.allAmountLabel.text = [NSString stringWithFormat:@"共%ld种药",goodsArr.count];
               
            }else{
                NSInteger imageCount = goodsArr.count;
                for (NSInteger i = 0; i<3 && i<imageCount; i++) {
                    NSDictionary *goodsDic = [NSDictionary dictionaryWithDictionary:goodsArr[i]];
                    if (i==0) {
                        [cell.cellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[goodsDic objectForKey:@"goodsImg"]]] placeholderImage:[UIImage imageNamed:@"shopping_image.png"] ];
                    }else if (i==1){
                        [cell.cellImage2 setHidden:NO];
                        [cell.cellImage2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[goodsDic objectForKey:@"goodsImg"]]] placeholderImage:[UIImage imageNamed:@"shopping_image.png"] ];
                    }else if (i==1){
                        [cell.cellImage3 setHidden:NO];
                        [cell.cellImage3 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[goodsDic objectForKey:@"goodsImg"]]] placeholderImage:[UIImage imageNamed:@"shopping_image.png"] ];
                    }
                }
            }
            
            
            NSInteger btnState = [[NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]] integerValue];
            [cell setBtnState:btnState];
        }else{
            UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,60,kScreen_Width,43)];
            nameLabel.numberOfLines = 1;
            nameLabel.clipsToBounds = YES;
            nameLabel.layer.cornerRadius = 4;
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:15];
            nameLabel.backgroundColor = RGB(85, 206, 84);
            nameLabel.textColor = [UIColor whiteColor];
            nameLabel.text = @"暂无订单数据";
            cell.accessoryView = nameLabel;
        }
        
        return cell;

    }else{
        static NSString *CellIdentifier = @"HNOrderConsultCell";
        
        HNOrderConsultCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        if (_docterListSource.count > 0) {

            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.cellName.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"sellerNickname"]];
            cell.cellDes.text= [NSString stringWithFormat:@"%@元图文资讯",[orderDic objectForKey:@"money"]];
            cell.cellTime.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"createTime"]];
   
            [cell.cellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[orderDic objectForKey:@"sellerPhoto"]]] placeholderImage:[UIImage imageNamed:@"D99GN4P63Q4F@2x.png"] ];
            NSInteger btnState = [[NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]] integerValue];
            [cell changeState:btnState];
        }else{
            UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,60,kScreen_Width,43)];
            nameLabel.numberOfLines = 1;
            nameLabel.clipsToBounds = YES;
            nameLabel.layer.cornerRadius = 4;
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:15];
            nameLabel.backgroundColor = RGB(85, 206, 84);
            nameLabel.textColor = [UIColor whiteColor];
            nameLabel.text = @"暂无订单数据";
            cell.accessoryView = nameLabel;
        }
        
        return cell;

    }
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([_orderType isEqualToString:orderType_my]) {
        OrderDetailController *orderDetailVC = [[OrderDetailController alloc]init];
        
        NSDictionary *orderDic = _docterListSource[indexPath.row];
        NSLog(@"%@",orderDic);
        
        orderDetailVC.orderSn = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"orderSn"]];
         orderDetailVC.orderState = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]];
        
        orderDetailVC.orderDic = orderDic;
        
        [self.navigationController pushViewController:orderDetailVC animated:YES];
    }else{
        NSDictionary *orderDic = _docterListSource[indexPath.row];
        HNOrderDetailController *orderDetailVC = [[HNOrderDetailController alloc]init];
        
        orderDetailVC.orderSn = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"orderSn"]];
        
        orderDetailVC.orderState = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]];
        
        [self.navigationController pushViewController:orderDetailVC animated:YES];
    }
}


#pragma mark - HNMyOrderTableCellDelegate

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell deleteIndexPath:(NSIndexPath *)indexPath{
    _selectedRow = indexPath.row;
    
    
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"系统提示" message:@"确认删除此订单?" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
    alert.tag = 101;
    [alert show];
    
}

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell payIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *orderDic = _docterListSource[indexPath.row];
    HNPayTypeController *orderDetailVC = [[HNPayTypeController alloc]init];
    
    orderDetailVC.orderSn = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"orderSn"]];
    
    [self.navigationController pushViewController:orderDetailVC animated:YES];
}

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell sureIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *orderDic = _docterListSource[indexPath.row];
    NSString *orderSn = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"orderSn"]];
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:static_sessionId,@"sessionId",nil];
    
    [param setObject:orderSn forKey:@"orderSn"];

    
    NSLog(@"param = %@",param);
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_order_sureReceive parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"确认收货失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            

            [self showHint:@"确认收货成功"];
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"确认收货失败"];
    }];

}

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell pushDeliveryIndexPath:(NSIndexPath *)indexPath{
    [self showHint:@"您的支持是商家的动力"];
}

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell viewLogisticsIndexPath:(NSIndexPath *)indexPath{

}

-(void)HNMyOrderTableCell:(HNMyOrderTableCell *)cell contectServiceIndexPath:(NSIndexPath *)indexPath{
    NSString *phoneNumberURLString = [@"tel://" stringByAppendingString:@"888-88888888"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURLString]];
}

#pragma mark - cell协议实现的方法

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag==101 && alertView.cancelButtonIndex==buttonIndex) {
        [self deleteOrder];
    }
}

-(void)deleteOrder{
    NSLog(@"%ld",_selectedRow);
    
    NSDictionary *orderDic = _docterListSource[_selectedRow];
    NSString *orderSn = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"orderSn"]];
    
    NSMutableDictionary *param = nil;
    param = [NSMutableDictionary dictionaryWithObjectsAndKeys:static_sessionId,@"sessionId",orderSn,@"orderSn",nil];
    [param setObject:@"0" forKey:@"type"];
    
    NSLog(@"param = %@",param);
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_order_delete parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"删除订单失败"];
            _selectedRow = selectedRow_OriginalValue;
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            
            [self showHint:@"删除成功"];
            [_docterListSource removeObjectAtIndex:_selectedRow  ];
              [_orderListTableView reloadData];
            _selectedRow = selectedRow_OriginalValue;
          
            
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
            
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"删除订单失败"];
        _selectedRow = selectedRow_OriginalValue;
    }];

}



#pragma mark - 获取消息
-(void)getDoctorMessage:(NSInteger)tag{

   
    _docterListCount = 0;
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:static_sessionId,@"sessionId",nil];
    [param setObject:[EMClient sharedClient].currentUsername forKey:@"buyerUsername"];
    NSString *status = nil;
    if ([_orderType isEqualToString:orderType_my]) {
        if (_choiceState == 3) {
            status = @"21";
        }else{
            status = [NSString stringWithFormat:@"%ld",_choiceState - 1];
        }
        if (_choiceState == 4) {
            status = @"22";
        }
    }else{
        if (_choiceState == 3) {
            status = @"11";
        }else{
            status = [NSString stringWithFormat:@"%ld",_choiceState - 1];
        }
        if (_choiceState == 4) {
            status = @"3";
        }
    }

    if (![status isEqualToString:@"-1"]) {
        [param setObject:status forKey:@"status"];
    }
    if ([_orderType isEqualToString:orderType_my]) {
         [param setObject:@"0" forKey:@"type"];
    }else{
        [param setObject:@"1" forKey:@"type"];
    }
   
//    [param setObject:_cur forKey:@"cur"];
    NSLog(@"param = %@",param);
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_order_consult parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"获取医生列表失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            NSArray * obj = [NSArray arrayWithArray:[data objectForKey:@"obj"]];
            NSLog(@"------obj = %@",obj);
            [self.docterListSource removeAllObjects];
            for (int i = 0; i < obj.count; i ++) {
                NSLog(@"%@",obj[i]);
                [self.docterListSource addObject:obj[i]];
            }
            
            NSLog(@"===self.docterListSource = %@",self.docterListSource);
            
            [_orderListTableView reloadData];
             [_orderListTableView.mj_header endRefreshing];
            [_orderListTableView.mj_footer endRefreshing];
        
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
             [_orderListTableView.mj_header endRefreshing];
            [_orderListTableView.mj_footer endRefreshing];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"获取医生列表失败"];
         [_orderListTableView.mj_header endRefreshing];
        [_orderListTableView.mj_footer endRefreshing];
    }];
    
    
}



@end
